﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
using WebAppMatrix.Extensions;

namespace WebAppMatrix
{
    public class MatrixManager
    {
        private static CultureInfo defaultCultureInfo = new CultureInfo("zh-cn");
        /// <summary>
        /// 获得默认语言文化信息
        /// </summary>
        public static CultureInfo DefaultCultureInfo
        {
            get
            {
                return defaultCultureInfo;
            }
        }

        private static Encoding defaultEncoding = Encoding.UTF8;
        /// <summary>
        /// 获取默认的编码方式
        /// </summary>
        public static Encoding DefaultEncoding
        {
            get
            {
                return defaultEncoding;
            }
        }

        private static Caching.CacheBase cacheProvider = null;
        /// <summary>
        /// 应用程序缓存，如果不存在，则使用WebAppMatrix.Caching.NoCacheProvider
        /// </summary>
        public static Caching.CacheBase CacheProvider
        {
            get
            {
                if (cacheProvider == null)
                {
                    if (Settings.CacheProvider.IsNullOrEmpty())
                        cacheProvider = new Caching.NoCacheProvider();
                    else
                        cacheProvider = ReflectionExtensions.CreateInstence<Caching.CacheBase>(
                            Settings.CacheProvider);
                }

                return cacheProvider;
            }
        }

        private static Configuration.MatrixSetting settings;
        public static Configuration.MatrixSetting Settings
        {
            get
            {
                if (settings == null)
                {
                    settings = new Configuration.MatrixSetting();
                }

                return settings;
            }
        }
    }
}
